#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 10;
int n, p;
int arr[N];
int main()
{
    cin >> n >> p;
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);

    int ret = 0, left = 0, right = 0;
    p *= 2;

    while (right < n)
    {
        while (arr[right] - arr[left] > p)
        {
            left++;
        }
        ret = max(ret, right - left + 1);
        right++;
    }

    cout << ret << endl;

    return 0;
}